home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0051_DBGrid that shows images.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-24  |  1.3 KB  |  67 lines

  1.  
  2. {
  3. // DBPICGRD.PAS (C) 1995 W. Raike
  4. //              ALL RIGHTS RESERVED.
  5. //
  6. //    DESCRIPTION:
  7. //      Data-aware grid that can display graphic fields.
  8. //    REVISION HISTORY:
  9. //      15/04/95  Created.    W. Raike
  10. }
  11.  
  12. unit DBPicGrd;
  13.  
  14. interface
  15.  
  16. uses
  17.   DBGrids, DB, DBTables, Grids, WinTypes, Classes, Graphics;
  18.  
  19. type
  20.   TDBPicGrid = class(TDBGrid)
  21.   protected
  22.     procedure DrawDataCell(const Rect: TRect;
  23.       Field: TField; State: TGridDrawState); override;
  24.   public
  25.     constructor Create(AOwner : TComponent); override;
  26.   published
  27.     property DefaultDrawing default False;
  28.   end;
  29.  
  30. procedure Register;
  31.  
  32. implementation
  33.  
  34. constructor TDBPicGrid.Create(AOwner : TComponent);
  35. begin
  36.   inherited Create(AOwner);
  37.   DefaultDrawing := False;
  38. end;
  39.  
  40. procedure TDBPicGrid.DrawDataCell(const Rect: TRect; Field: TField;
  41. State: TGridDrawState);
  42. var
  43.   bmp : TBitmap;
  44. begin
  45.   with Canvas do
  46.   begin
  47.     FillRect(Rect);
  48.     if Field is TGraphicField then
  49.         try
  50.           bmp := TBitmap.Create;
  51.           bmp.Assign(Field);
  52.           Draw(Rect.Left, Rect.Top, bmp);
  53.         finally
  54.           bmp.Free;
  55.         end
  56.     else
  57.       TextOut(Rect.Left, Rect.Top, Field.Text);
  58.   end;
  59. end;
  60.  
  61. procedure Register;
  62. begin
  63.   RegisterComponents('Custom', [TDBPicGrid]);
  64. end;
  65.  
  66. end.
  67.